﻿using System;
using SqlSugar;

namespace Tools.Data.ISqlFunc
{
    public class TSqlFunc : ISqlFunc
    {
        public SqlFuncExternal SqlFuncExternal => new SqlFuncExternal
        {
            UniqueMethodName = "CharIndex",
            MethodValue = (expInfo, dbType, expContext) =>
            {
                if (dbType == DbType.SqlServer)
                    return $" charindex('{expInfo.Args[0].MemberValue}',{expInfo.Args[1].MemberName}) >0";
                else
                    throw new Exception("未实现");
            }
        };
        /// <summary>
        /// 字符,分割
        /// </summary>
        /// <typeparam name="TValue"></typeparam>
        /// <typeparam name="TColumn"></typeparam>
        /// <param name="value"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public static bool CharIndex<TValue, TColumn>(TValue value, TColumn column)
        {
            throw new NotSupportedException("Can only be used in expressions");
        }
    }
}
